#Alternative mass killing thresholds
library(dplyr)
data_test$mk_onset_200<-ifelse(data_test$gov_deaths_civilians>=200, 1, 0)
data_test$mk_onset_500<-ifelse(data_test$gov_deaths_civilians>=500, 1, 0)
data_test$mk_onset_1000<-ifelse(data_test$gov_deaths_civilians>=1000, 1, 0)
data_test<-data_test %>%
  group_by(iso3c) %>%
  mutate(mk_onset_500_consec=lag(mk_onset_500),
         mk_onset_200_consec=lag(mk_onset_200),
         mk_onset_1000_consec=lag(mk_onset_1000))

data_test$mk_onset_500[data_test$mk_onset_500_consec==1]<-0
data_test$mk_onset_200[data_test$mk_onset_200_consec==1]<-0
data_test$mk_onset_1000[data_test$mk_onset_1000_consec==1]<-0

table(data_test$mk_onset_200)
table(data_test$mk_onset_500)
table(data_test$mk_onset_1000)

#Gov battle deaths
#CW 1
#Table F1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-63]
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")
#None occuring in democracies, record TCR as 0

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Hybrid regimes
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-19]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Autocratic regimes
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-14]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-53]
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-9]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_500")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-63]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-19]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-14]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-53]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-9]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_500")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902) 
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset_500")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Nonviolent protest (Table F2)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)

for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")




#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset_500")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset_500")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Unsuccessful coup (Table F3)
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-63]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-19]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-14]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-53]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-9]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_500")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_500")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_500", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Alterantive mass killing thresholds 200

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Hybrid regimes
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Autocratic regimes
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Gov battle deaths
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "gov_battle_deaths_escalation", "mk_onset_200")]
t<-t[which(t$gov_battle_deaths_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "gov_battle_deaths_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Rebel civilian killing
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "reb_deaths_civilians_escalation", "mk_onset_200")]
t<-t[which(t$reb_deaths_civilians_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "reb_deaths_civilians_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-28]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-23]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-24]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Conflict spillover
#CW 1 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2 
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "spillover", "mk_onset_200")]
t<-t[which(t$spillover>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "spillover")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-105]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-105]
countries<-countries[-85] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-105]
countries<-countries[-96] 
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-44]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-44]
countries<-countries[-31] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-44] 
countries<-countries[-31]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-19] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-84]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-84] #Remove Sri Lanka (listwise deletion not built in to function )
countries<-countries[-65]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-84] 
countries<-countries[-65] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-21] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-18] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-87]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-87]
countries<-countries[-68] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-87] 
countries<-countries[-68] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")




#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-15] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-14] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-10] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Nonviolent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "nonviolent_protest_escalation", "mk_onset_200")]
t<-t[which(t$nonviolent_protest_escalation>-99), ]

m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7] 
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "nonviolent_protest_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-105]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-105]
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-105]
countries<-countries[-96]
countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-85]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
#countries<-countries[-85]
#countries<-countries[-130]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-44]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-44]
countries<-countries[-31]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-44]
countries<-countries[-31]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")

#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-19]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-84]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-84]
countries<-countries[-65]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-84]
countries<-countries[-65]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-21]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-18]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-87]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-87]
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-87]
countries<-countries[-68]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-15]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-14]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-10]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Violent protest
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")

#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1 & (data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1)), c("iso3c", "protesterviolence_escalation", "mk_onset_200")]
t<-t[which(t$protesterviolence_escalation>-99), ]
m<-list()
countries<-unique(t$iso3c)
countries<-countries[-7]
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "protesterviolence_escalation")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")



#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$all==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$democracy_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$hybrid_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$autocracy_vdem==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which(data_test$low_rol==1 & data_test$high_instability==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Unsuccessful coup
data_test$unsuccessful_coup<-(-99)
data_test$unsuccessful_coup[data_test$pt_attempt==1 & data_test$pt_success==0]<-1
data_test$unsuccessful_coup[data_test$pt_attempt==0]<-0

#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")


#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "unsuccessful_coup", "mk_onset_200")]
t<-t[which(t$unsuccessful_coup>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "unsuccessful_coup")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


#Successful coup
data_test$pt_success[is.na(data_test$pt_success)]<-(-99)
#CW 1
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=1, sigtest="shuffle.surrogate")


#CW 2
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=5, sigtest="shuffle.surrogate")

#CW 3
set.seed(042902)
t<-data_test[which((data_test$hybrid_vdem==1 | data_test$autocracy_vdem==1) & data_test$high_instability==1 & data_test$low_rol==1), c("iso3c", "pt_success", "mk_onset_200")]
t<-t[which(t$pt_success>-99), ]
m<-list()
countries<-unique(t$iso3c)
for (i in 1:length(countries)){
  d<-as.matrix(t[t$iso3c==countries[i], c("mk_onset_200", "pt_success")]) 
  m[[i]]<-d
}
CC.eca.aggregated.ts(m, delT = 4, tau=9, sigtest="shuffle.surrogate")


